package top.superflow.flow.config

import top.superflow.exception.RequestUnsupportedException
import top.superflow.flow.config.template.TemplateAble
import top.superflow.lang.{CollectionUtils, StringUtils}

trait Config extends Identifiable with TemplateAble {

  protected def getItemFromMetadata(k : String) : String = {
    if(StringUtils.isBlank(k)){
      throw new RequestUnsupportedException("The key should not be blank")
    }

    if(CollectionUtils.isEmpty(this.getMetadata)){
      throw new RequestUnsupportedException("The metadata is empty, you can get nothing for the key " + k)
    }

    if(!this.getMetadata.contains(k)){
      return StringUtils.EMPTY
    }

    this.getMetadata.get(k).get.toString
  }

  protected def containMetadata(k : String) : Boolean = {
    if(StringUtils.isBlank(k)){
      throw new RequestUnsupportedException("The key should not be blank")
    }

    if(CollectionUtils.isEmpty(this.getMetadata)){
      return false
    }

    if(!this.getMetadata.contains(k)){
      return false
    }

    return true
  }
}